class Milestone < ActiveRecord::Base
  has_many :tasks
  
  @pending = "Pending"
  @inProgress = "InProgress"
  @finished = "Finished"
  
  @status = [@pending, @inProgress, @finished]
  
  def self.status_names
  	return @status
  end
  
  def self.complete_percentage (milestone_id)
  	mil = self.find(:first, :conditions => ["id = ?", milestone_id])
  	if mil.nil?
  		return nil
  	else
  		finished_count = 0;
  		for task in mil.tasks
  			if task.status.to_i == @status.index(@finished)
  				finished_count +=1
  			end
  		end
  		return ((finished_count/mil.tasks.length.to_f) * 100).round
  	end	
  end
  
end
